"""
@File    :   validate.py
@Time    :   2024/03/25 10:44:35
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   租户相关的pydantic验证模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, conint

from src.schemas.validate import (
    BaseSearchValidateSchemaMixin,
    BaseValidateSchemaConfigMixin,
)


class TenantCreateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于创建租户的验证模型"""

    name: str = Field(default=..., min_length=1, max_length=200, description="租户名")
    status: bool = Field(default=True, description="状态")
    show_order: int = Field(default=1, ge=1, le=9999999, description="显示顺序")
    remark: str = Field(default="", min_length=1, max_length=300, description="备注")
    expiration_datetime: datetime = Field(default=..., description="过期时间")
    bind_domain: str = Field(
        default="",
        min_length=1,
        max_length=200,
        pattern=r"^(?:www\.)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})(?:/\S*)?$",
        description="绑定域名",
    )
    quota: int = Field(default=..., ge=0, lt=999999999, description="额度")
    tenant_package_id: int = Field(default=..., ge=1, description="租户套餐ID")
    admin_username: str = Field(
        default=..., min_length=1, max_length=20, description="租户默认管理员的用户名"
    )
    admin_password: str = Field(
        default=...,
        min_length=1,
        max_length=256,
        description="租户默认管理员的密码明文",
    )
    admin_name: str = Field(
        default=...,
        min_length=1,
        max_length=50,
        description="租户默认管理员的使用人姓名",
    )
    admin_remark: str = Field(
        default="",
        min_length=1,
        max_length=300,
        description="租户默认管理员的备注",
    )


class TenantUpdateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于修改租户的验证模型
    不可操作系统级别的租户(service.py)
    """

    id: int = Field(default=..., ge=1, description="主键")
    name: str = Field(default=..., min_length=1, max_length=200, description="租户名")
    status: bool = Field(default=True, description="状态")
    show_order: int = Field(default=1, ge=1, le=9999999, description="显示顺序")
    remark: str = Field(default="", min_length=1, max_length=300, description="备注")
    expiration_datetime: datetime = Field(default=..., description="过期时间")
    bind_domain: str = Field(
        default="",
        min_length=1,
        max_length=200,
        pattern=r"^(?:www\.)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})(?:/\S*)?$",
        description="绑定域名",
    )
    quota: int = Field(default=..., ge=0, lt=999999999, description="额度")
    tenant_package_id: int = Field(default=..., ge=1, description="租户套餐ID")


class TenantUpdateStatusValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于单独修改租户的状态的验证模型
    不可操作系统级别的租户(service.py)
    """

    id: int = Field(default=..., ge=1, description="主键")
    status: bool = Field(default=..., description="状态")


class TenantDeleteValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于删除租户的验证模型"""

    ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="需删除的主键列表"
    )


class TenantListSearchValidateSchema(BaseModel, BaseSearchValidateSchemaMixin):
    """用于查询租户套餐列表的验证模型"""

    name: str | None = Field(
        default=None,
        min_length=1,
        max_length=200,
        description="租户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    status: bool | None = Field(default=None, description="状态")
    is_system: bool | None = Field(default=None, description="是否系统租户")
    remark: str | None = Field(
        default=None,
        min_length=1,
        max_length=300,
        description="备注",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    expiration_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="过期时间",
        json_schema_extra={"allow_order": True},
    )
    bind_domain: str | None = Field(
        default=None,
        min_length=1,
        max_length=200,
        description="绑定域名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    quota: tuple[conint(ge=0, lt=999999999), conint(ge=0, lt=999999999)] = Field(
        default=None,
        description="额度",
        json_schema_extra={"allow_order": True},
    )
    create_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="创建时间",
        json_schema_extra={"allow_order": True},
    )
    update_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="修改时间",
        json_schema_extra={"allow_order": True},
    )
    creator_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="创建者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    updater_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="修改者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
